﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<skags.Models.PollModels>" %>
<%@ Import Namespace="skags.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Birta allar kannanir
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="navigation">
        <% Html.RenderPartial("AdminNavigation"); %>
    </div>
    <div id="content">
    <p><a href="/Admin/CreatePoll"><img src="../../Content/icons/create.png" alt="Ný könnun" /> Búa til könnun</a></p>
    <% foreach (var p in (IEnumerable<Poll>)ViewData["AllPolls"]) { %>
    <p>
    <a href="/Admin/DeletePoll/<%= p.ID %>" onclick="return confirm('Ertu viss um að þú viljir eyða þessari könnun?')"><img src="../../Content/icons/delete.png" alt="Eyða" /></a>
    <a href="/Admin/EditPoll/<%= p.ID %>"><img src="../../Content/icons/edit.png" alt="Breyta" /></a>
    </p>
        <table border="1">
            <tr>
                <th>
                    ID
                </th>
                <th>
                    Spurning
                </th>
                <%if (p.Option1 != null)%>
                <%{%>
                <th>
                    Svar 1
                </th>
                <%}%>
                <%if (p.Option2 != null)%>
                <%{%>
                <th>
                    Svar 2
                </th>
                <%}%>
                <%if (p.Option3 != null)%>
                <%{%>
                <th>
                    Svar 3
                </th>
                <%}%>
                <%if (p.Option4 != null)%>
                <%{%>
                <th>
                Svar 4
                </th>
                <%}%>
                <%if (p.Option5 != null)%>
                <%{%>
                <th>
                    Svar 5
                </th>
                <%}%>
            </tr>
            <tr>
                <td>
                    <%: p.ID%>
                </td>
                <td>
                    <%: p.Question%>
                </td>
                <%if (p.Option1 != null)%>
                <%{%>
                <td>
                    <%:p.Option1%>    
                </td>
                <%}%>
                <%if (p.Option2 != null)%>
                <%{%>
                <td>
                    <%:p.Option2%>    
                </td>
                <%}%>
                <%if (p.Option3 != null)%>
                <%{%>
                <td>
                    <%:p.Option3%>    
                </td>
                <%}%>
                <%if (p.Option4 != null)%>
                <%{%>
                <td>
                    <%:p.Option4%>    
                </td>
                <%}%>
                <%if (p.Option5 != null)%>
                <%{%>
                <td>
                    <%:p.Option5%>    
                </td>
                <%}%>
            </tr>
        </table>
       
        <%
        if(p.Vote1 == null)
        {
            p.Vote1 = 0;
        }   
        %>
        <%
        if(p.Vote2 == null)
        {
            p.Vote2 = 0;
        }   
        %>
        <%
        if(p.Vote3 == null)
        {
            p.Vote3 = 0;
        }   
        %>
        <%
        if(p.Vote4 == null)
        {
            p.Vote4 = 0;
        }   
        %>
        <%
        if(p.Vote5 == null)
        {
            p.Vote5 = 0;
        }   
        %>



        <%if (p.Vote1 + p.Vote2 + p.Vote3 + p.Vote4 + p.Vote5 > 0)%>
        <%{%>
            <%if(p.Vote1 > 0) %>
            <%{%>
                <p>Svar 1 fékk <%= Math.Round((((double)(p.Vote1) / (double)(p.Vote1 + p.Vote2 + p.Vote3 + p.Vote4 + p.Vote5))*100),2)%> % atkvæða.</p>
            <%}%>
            <%if (p.Vote2 > 0)%>
            <%{%>
                <p>Svar 2 fékk <%= Math.Round((((double)(p.Vote2) / (double)(p.Vote1 + p.Vote2 + p.Vote3 + p.Vote4 + p.Vote5))*100),2)%> % atkvæða.</p>
            <%}%>
            <%if (p.Vote3 > 0)%>
            <%{%>
                <p>Svar 3 fékk <%= Math.Round((((double)(p.Vote3) / (double)(p.Vote1 + p.Vote2 + p.Vote3 + p.Vote4 + p.Vote5))*100),2)%> % atkvæða.</p>
            <%}%>
            <%if (p.Vote4 > 0)%>
            <%{%>
                <p>Svar 4 fékk <%= Math.Round((((double)(p.Vote4) / (double)(p.Vote1 + p.Vote2 + p.Vote3 + p.Vote4 + p.Vote5))*100),2)%> % atkvæða.</p>
            <%}%>
            <%if (p.Vote5 > 0)%>
            <%{%>
                <p>Svar 5 fékk <%= Math.Round((((double)(p.Vote5) / (double)(p.Vote1 + p.Vote2 + p.Vote3 + p.Vote4 + p.Vote5))*100),2)%> % atkvæða.</p>
            <%}%>
         <%}%>
         <%if(p.Vote1 + p.Vote2 + p.Vote3 + p.Vote4 + p.Vote5 == 0) %>
         <%{%>
            <p> Engin atkvæði hafa verið greidd</p>
         <%}%><br />
    <%}%>
    </div>
</asp:Content>
